package com.infoland.afanmall.model.youXuan.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.LogKit;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.model.youXuan.entity.PtEntity;
import com.infoland.afanmall.model.youXuan.entity.PtResponse;
import com.infoland.afanmall.model.youXuan.entity.YouXuanType;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

public class PtAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    private int layoutPosition = 0;
    private Context context;
    private FragmentActivity activity;

    public PtAdapter(List data, Context context, FragmentActivity activity) {
        super(data);
        this.context = context;
        this.activity = activity;
        addItemType(YouXuanType.PT_BEAN_PT, R.layout.you_xuan_pt_item1);
        addItemType(YouXuanType.PT_BEAN_XL, R.layout.you_xuan_pt_xi_lie);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        PtResponse.ListBean listBean = (PtResponse.ListBean) item;
        int adapterPosition = helper.getAdapterPosition();
        switch (helper.getItemViewType()) {
            /*** 普通商品**/
            case YouXuanType.PT_BEAN_PT:
                helper.setText(R.id.ys_pt_item_txt_price1, "￥" + listBean.getG_price());
                TextView view = helper.getView(R.id.ys_pt_item_txt_price2);
                view.setText("￥" + listBean.getG_origin_price());
                ToolsKit.setTextDelete(view);
                helper.setText(R.id.ys_pt_item_txt_name, listBean.getG_name() + "");
                helper.setText(R.id.ys_pt_item_txt_content, listBean.getG_introduction() + "");
                AppCompatImageView appCompatImageView = helper.getView(R.id.ys_pt_item_image);
                ToolsKit.setImgView(listBean.getF_url(), appCompatImageView);
                helper.getView(R.id.pt_item_layout).setOnClickListener(v -> {
                    ptLinster.onClick(helper, YouXuanType.PT, adapterPosition, item, "img");
                });
                helper.getView(R.id.pt_xin).setOnClickListener(v -> {
                    ptLinster.onClick(helper, YouXuanType.PT, adapterPosition, item, "xin");
                });
                helper.getView(R.id.pt_cart).setOnClickListener(v -> {
                    ptLinster.onClick(helper, YouXuanType.PT, adapterPosition, item, "cart");
                });
                break;
            /*** 系列商品 **/
            case YouXuanType.PT_BEAN_XL:
                LogKit.E("系列商品 ---->   ", "  系列商品");
                helper.getView(R.id.pt_xiang_xi).setOnClickListener(v -> {
                    ptLinster.onClick(helper, YouXuanType.PT, adapterPosition, item, "xi_lie");
                });
                AppCompatImageView imageView = helper.getView(R.id.ys_pt_item_image);
                ToolsKit.setImgView(listBean.getGs_image(), imageView);

                break;
        }
    }


    public interface PtLinster {
        void onClick(BaseViewHolder holder, int itemType, int position, Object item, String item_type);
    }

    private PtLinster ptLinster;

    public void setPtLinster(PtLinster ptLinster) {
        this.ptLinster = ptLinster;
    }


}
